package cn.edu.sgu.www.mhxysy.controller.children_equipment;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.children_equipment.ChildrenEquipmentAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.children_equipment.ChildrenEquipmentAttribute;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.children_equipment.ChildrenEquipmentAttributeService;
import cn.edu.sgu.www.mhxysy.vo.except.AttributeVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "子女装备属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/children_equipment_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChildrenEquipmentAttributeController {

	private final ChildrenEquipmentAttributeService childrenEquipmentAttributeService;

	@Autowired
	public ChildrenEquipmentAttributeController(ChildrenEquipmentAttributeService childrenEquipmentAttributeService) {
		this.childrenEquipmentAttributeService = childrenEquipmentAttributeService;
	}

	@ApiOperation("添加子女装备属性")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated ChildrenEquipmentAttributeDTO childrenEquipmentAttributeDTO) {
		childrenEquipmentAttributeService.insert(childrenEquipmentAttributeDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除子女装备属性")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(
			@ApiParam(name = "id", value = "子女装备属性ID", required = true)
			@NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
		childrenEquipmentAttributeService.deleteById(id);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过ID修改子女装备属性")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated ChildrenEquipmentAttributeDTO childrenEquipmentAttributeDTO) {
		childrenEquipmentAttributeService.updateById(childrenEquipmentAttributeDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("查询子女装备属性列表")
	@RequestMapping(value = "/selectAttributes", method = RequestMethod.GET)
	public JsonResult<List<AttributeVO>> selectAttributes(
			@ApiParam(name = "equipmentId", value = "子女装备ID", required = true)
			@NotBlank(message = "子女装备" + CustomMessages.ID_NOT_NULL) String equipmentId) {
		List<AttributeVO> list = childrenEquipmentAttributeService.selectAttributes(equipmentId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过子女装备ID查询子女装备属性")
	@RequestMapping(value = "/selectByEquipmentId", method = RequestMethod.GET)
	public JsonResult<List<ChildrenEquipmentAttribute>> selectByEquipmentId(
			@ApiParam(name = "equipmentId", value = "子女装备ID", required = false)
			@RequestParam(required = false) String equipmentId) {
		List<ChildrenEquipmentAttribute> list = childrenEquipmentAttributeService.selectByEquipmentId(equipmentId);

		return JsonResult.success(null, list);
	}

}